package im.yisme.model;

import java.io.IOException;
import java.util.ArrayList;

import im.yisme.model.fileio.LyricsWriter;
import im.yisme.vo.LyricsVO;

public class Lyrics {

	public static final int OFFICIAL = 1;
	public static final int ORIGINAL = 2;
	public static final int UNORIGINAL = 3;
	
	private long id;
	private String filePath;
	private String artist;
	private String name;
	private LyricsHeader lyricsHeader;
	private ArrayList<LyricsAction> lyricsActions;
	private int source;
	private int score;
	private int noteNum;
	private String totalTime;
	
	public Lyrics(long id, String artist, String name, String filePath, int source) {
		super();
		this.id = id;
		this.artist = artist;
		this.name = name;
		this.filePath = filePath;
		this.source = source;
		
		score = 0;
		noteNum = 0;
		totalTime = "0:00";
	}

	/**
	 * 取得歌谱ID
	 * @return
	 */
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	/**
	 * 取得演奏者
	 * @return
	 */
	public String getArtist() {
		return artist;
	}

	public void setArtist(String artist) {
		this.artist = artist;
	}

	/**
	 * 取得歌谱名
	 * @return
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 歌谱来源
	 * @return
	 */
	public int getSource(){
		return source;
	}
	
	public void setSource(int source){
		this.source = source;
	}

	/**
	 * 取得文件路径
	 * @return
	 */
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public LyricsHeader getLyricsHeader() {
		return lyricsHeader;
	}

	public void setLyricsHeader(LyricsHeader lyricsHeader) {
		this.lyricsHeader = lyricsHeader;
	}

	public ArrayList<LyricsAction> getLyricsActions() {
		return lyricsActions;
	}

	public void setLyricsActions(ArrayList<LyricsAction> lyricsActions) {
		this.lyricsActions = lyricsActions;
	} 
	
	public void setRemoteId(long remoteId) throws IOException{
		lyricsHeader.setRemoteId(remoteId);
		new LyricsWriter().write(this);
	}
	
	public int getActionCount(){
		return lyricsActions == null ? -1 : lyricsActions.size();
	}

	/**
	 * 取得歌谱在服务器上的ID
	 * @return
	 */
	public long getRemoteId(){
		return lyricsHeader == null ? -1 : lyricsHeader.getRemoteId();
	}
	
	/**
	 * 是否已上传
	 * @return
	 */
	public boolean isUploaded(){
		return lyricsHeader != null ? lyricsHeader.isUploaded() : false;
	}
	
	/**
	 * 是否已评价
	 * @return
	 */
	public boolean isEvaluated(){
		return lyricsHeader != null ? lyricsHeader.isEvaluated() : false;
	}

	public LyricsVO toVO(){
		return new LyricsVO(this);
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getNoteNum() {
		return noteNum;
	}

	public void setNoteNum(int noteNum) {
		this.noteNum = noteNum;
	}

	public String getTotalTime() {
		return totalTime;
	}

	public void setTotalTime(String totalTime) {
		this.totalTime = totalTime;
	}
}
